﻿using System;
using System.Data;
using System.Xml.Serialization;
/******************************************************************************************************************
 * 
 * 
 * 说　明： CommandInfo对象(版本：Version1.0.0)
 * 作　者：李朝强
 * 日　期：2015/05/19
 * 修　改：
 * 参　考：http://my.oschina.net/lichaoqiang/
 * 备　注：暂无...
 * 
 * 
 * ***************************************************************************************************************/
namespace SQLMap.Core
{

    /// <summary>
    /// <![CDATA[command]]>
    /// </summary>
    [Serializable]
    [XmlType("command")]
    public sealed class Command
    {
        /// <summary>
        /// <![CDATA[调用名称]]>
        /// </summary>
        [XmlAttribute(AttributeName = "id")]
        public string Id { get; set; }

        /// <summary>
        /// <![CDATA[SQL]]>
        /// </summary>
        [XmlElement("commandText")]
        public string CommandText { get; set; }

        /// <summary>
        /// <![CDATA[类型]]>
        /// </summary>
        [XmlElement("commandType")]
        public CommandType CommandType { get; set; }

        /// <summary>
        /// <![CDATA[参数]]>
        /// </summary>
        [XmlArray("parameters")]
        public ParameterCollection Parameters { get; set; }

        /// <summary>
        ///<![CDATA[条件]]>
        /// </summary>
        [XmlElement("condition")]
        public Condition.Condition Condition { get; set; }

        /// <summary>
        /// <![CDATA[排序]]>
        /// </summary>
        [XmlElement("orderBy")]
        public string OrderBy { get; set; }

        /// <summary>
        ///<![CDATA[group by 分组]]>
        /// </summary>
        [XmlElement("groupBy")]
        public string GroupBy { get; set; }


        /// <summary>
        /// <![CDATA[生成Command对象]]>
        /// </summary>
        /// <param name="command"><![CDATA[command对象]]></param>
        /// <param name="parameters"><![CDATA[(可选)参数]]></param>
        /// <returns></returns>
        [MTAThread]
        public IDbCommand Build(IDbConnection connection, object parameters = null)
        {
            return SqlMapConfig.commandParser.Build(command: this, connection: connection, parameters: parameters);
        }


    }
}
